package com.acwing.partition9;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/5 17:56
 */
public class AC885求组合数I {

    private static final int N = 2010;
    private static final int[][] dp = new int[N][N];
    private static final int MOD = (int) (1e9 + 7);

    static {
        //预处理出来组合数，i表示物品个数，j表示从i中选取的个数
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= i; j++) {
                dp[i][j] = j == 0 ? 1 : (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        while (n-- > 0) {
            s = reader.readLine().split(" ");
            int a = Integer.parseInt(s[0]), b = Integer.parseInt(s[1]);
            writer.write(dp[a][b] + "\n");
        }
        writer.flush();
    }
}
